﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using System.Xml;
using SMSSnew.smss_web_reference;
using SMSSnew.CLASSES;

namespace SMSSnew.DATA
{
    public class userAccountDA
    {
        smss_web_service_app srv;
        DataTable dt;
        readXML XMLreader;

        private string user_name;
        private string password;
        private string email;
        private string phone_num;
        private string class_id;
        private string sec_question;
        private string sec_answer;
        private string full_name;


        

        public userAccountDA()
        {

        }

        public DataTable loadGrade_id()
        {
            string query = "";
            try
            {
                srv = new smss_web_service_app();
                XMLreader = new readXML();
                query = XMLreader.readXMLtxt("loadGrade", "~/DATA/XML/UserAccountXML.xml");

                //query = query.Replace("@username", objUser.user_name);
                //query = query.Replace("@password", objUser.password);

                dt = srv.Search(query);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        public DataTable loadClass_id()
        {
            string query = "";
            try
            {
                srv = new smss_web_service_app();
                XMLreader = new readXML();
                query = XMLreader.readXMLtxt("loadClass", "~/DATA/XML/UserAccountXML.xml");

                //query = query.Replace("@username", objUser.user_name);
                //query = query.Replace("@password", objUser.password);

                dt = srv.Search(query);

            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        public DataTable createUser(string username, string password, string sec_question, string sec_answer, string full_name, string email, string phone_num,string userType)
        {
            string query = "";
            try
            {
                srv = new smss_web_service_app();
                XMLreader = new readXML();
                query = XMLreader.readXMLtxt("createUser", "~/DATA/XML/UserAccountXML.xml");

                query = query.Replace("@user_name", username);
                query = query.Replace("@pword", password);
                query = query.Replace("@sec_question", sec_question);
                query = query.Replace("@sec_answer", sec_answer);
                query = query.Replace("@full_name", full_name);
                query = query.Replace("@email", email);
                query = query.Replace("@phone_number", phone_num);
                query = query.Replace("@user_type", userType);

               

                dt = srv.Search(query);

            }
            catch (Exception ex)
            {
                throw ex;
            }
        
            return dt;

        }

        public DataTable loadUser(string user_name)
        {
            string query = "";
            try
            {
                srv = new smss_web_service_app();
                XMLreader = new readXML();
                query = XMLreader.readXMLtxt("loadUser", "~/DATA/XML/UserAccountXML.xml");

                query = query.Replace("@user_name", user_name);
                //query = query.Replace("@password", objUser.password);

                dt = srv.Search(query);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        public void updateUser(string username, string password, string sec_question, string sec_answer, string full_name, string email, string phone_num)
        {
            string query = "";
            try
            {
                srv = new smss_web_service_app();
                XMLreader = new readXML();
                query = XMLreader.readXMLtxt("editUser", "~/DATA/XML/UserAccountXML.xml");

                query = query.Replace("@user_name", username);
                query = query.Replace("@pword", password);
                query = query.Replace("@sec_question", sec_question);
                query = query.Replace("@sec_answer", sec_answer);
                query = query.Replace("@full_name", full_name);
                query = query.Replace("@email", email);
                query = query.Replace("@phone_number", phone_num);

                srv.Modify(query);
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        public void deleteUser(string user_name)
        {
            string query = "";
         //   dt = new DataTable();
            try
            {
                srv = new smss_web_service_app();
                XMLreader = new readXML();
                query = XMLreader.readXMLtxt("deleteUser", "~/DATA/XML/UserAccountXML.xml");

                query = query.Replace("@user_name", user_name);
                //query = query.Replace("@password", objUser.password);

                srv.Modify(query);
            }
            catch (Exception ex)
            {
                throw ex;
            }
          //  return dt;
        }


        public void checkUser(string user_name)
        {
            string query = "";

            try
            {
                srv = new smss_web_service_app();
                XMLreader = new readXML();
                query = XMLreader.readXMLtxt("checkUser", "~/DATA/XML/userAccount.xml");

                //query = query.Replace("@user_name", user_name);
                //query = query.Replace("@password", objUser.password);

                dt = srv.Search(query);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            //return dt;
        }
        }

    }

